package ita.class1.group2.supermarket.administrator.controller;


import ita.class1.group2.supermarket.administrator.pojo.AdStore;
import ita.class1.group2.supermarket.administrator.pojo.Store;
import ita.class1.group2.supermarket.administrator.service.AdFormService;
import ita.class1.group2.supermarket.administrator.service.StoreService;
import ita.class1.group2.supermarket.common.util.RespMessageFactory;
import ita.class1.group2.supermarket.common.annotation.Autowired;
import ita.class1.group2.supermarket.common.annotation.Component;
import ita.class1.group2.supermarket.common.annotation.RequestMapping;
import ita.class1.group2.supermarket.common.pojo.ResponseMessage;

import java.util.List;
import java.util.Map;

@Component
public class CApiController {
    @Autowired
    AdFormService adFormService;
    @Autowired
    StoreService storeService;

    /**
     * 获取广告信息
     *
     * @throws Exception
     */
    @RequestMapping("/m/ads")
    public ResponseMessage getAd() throws Exception {
        List<AdStore> confirmAd = adFormService.getConfirmAd();
        return RespMessageFactory.createSuccessMessage(confirmAd);
    }

    /**
     * 获取广告信息
     *
     * @throws Exception
     */
    @RequestMapping("/m/adWithId")
    public ResponseMessage getAdByid(Map<String,String> map) throws Exception {
        String aid = map.get("aid");
        AdStore confirmAd = adFormService.getConfirmAdById(aid);
        return RespMessageFactory.createSuccessMessage(confirmAd);
    }
    /**
     * 获取stroe信息
     * @throws Exception
     */
    @RequestMapping("/c/api/available")
    public ResponseMessage available() throws Exception {
        List<Store> storeList = storeService.getAvailableStores();
        return RespMessageFactory.createSuccessMessage(storeList);
//        System.err.println(new String(JsonUtil.toJson(storeList).getBytes("ISO-8859-1"), "GBK"));
    }
}
